// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
import App from "./App";
import router from "./router";
import store from "./store";
import elementUI from "element-ui";
import vueCharts from "vue-chartjs";
import "element-ui/lib/theme-chalk/index.css";
import "styles/reset.css";
import "styles/elreset.css";
import "styles/iconfont.css";
import axios from "axios";
import Avue from "@smallwei/avue";
import "@smallwei/avue/lib/index.css";

Vue.config.productionTip = false;

Vue.use(Avue);
Vue.use(elementUI);
Vue.use(vueCharts);

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requireAuth)) {
    if (localStorage.token) {
      next();
    } else {
      // next()
      next({
        path: "/login",
        query: { redirect: to.fullPath }
      });
    }
  } else {
    next();
  }
});

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  store,
  axios,
  components: { App },
  template: "<App/>"
});
